package com.cloud.system.project.service.impl;

import com.cloud.api.job.JobTestFeign;
import com.cloud.api.weixin.WeixinTestFeign;
import com.cloud.system.project.mapper.UserMapper;
import com.cloud.system.project.service.ITestService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * Test 服务实现类
 * </p>
 *
 * @author Sam
 * @since 2021-05-17
 */
@Slf4j
@Service
public class TestServiceImpl implements ITestService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private JobTestFeign jobTestFeign;
    @Resource
    private WeixinTestFeign weixinTestFeign;

    @Override
    @GlobalTransactional
    @Transactional(rollbackFor = Exception.class)
    public void globalTranTest() {
        String xid = RootContext.getXID();
        log.info("System New Transaction Begins: " + xid);
        //用户状态-1
        userMapper.storeReduce("1002", 1);
        //日志状态-1
        jobTestFeign.seataReduceStore();
        //微信用户状态-1
        weixinTestFeign.seataReduceAmount();
        log.info("System New Transaction End: " + xid);
    }
}
